<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- $event -->
        <!-- 元素标签里面 -->
        <!-- <input @input="handleInput"/> -->
        <!-- 通过$event,实现如果既要传参,又要接受事件对象,$event就是事件对象 -->
        <input @input="handleInput(123,$event)"/>

        <!-- 组件上面 -->
        <!-- <my-component @add="handleAdd"></my-component> -->
        <!-- 通过$event,实现既要传参,又要接受子组件传过来数据,$event就是子组件传过来的数据 -->
        <my-component @add="handleAdd('hello',$event)"></my-component>
    </div>
</body>
<script>
Vue.component('my-component', {
    template: `
        <div>子组件
            <button @click="$emit('add', 123)">按钮</button>
        </div>
    `
})    
let vm = new Vue({
    el: '#app',
    data(){
        return {
        }
    },
    methods: {
        handleInput(num, e){
            console.log(num, e)
        },
        handleAdd(str, data){
            console.log(str,data)
        }
    },
})
</script>
</html>